
<%@page import="nnweboa.Userinfo"%>
<%@page import="java.util.List"%>

<%@page import="nnweboa.Unitls"%>
<%@page import="nnweboa.User"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="utf-8"%>
<%
	if (request.getHeader("Referer") != null
			&& !request.getHeader("Referer").isEmpty()) {
		String name = request.getParameter("username");
		String pass = request.getParameter("userpass");

		List<Userinfo> mailinfo = Unitls.findByMail(name,out); 
    
		if (mailinfo.size() > 0
				&& Unitls.testUser(mailinfo.get(0), pass)) {

			Cookie user = new Cookie("UserNameCookie", name);
			user.setMaxAge(-1); // need modify
			response.addCookie(user);

			int userright = Unitls.getUserRightBycookieName(name,out);
			if (userright == User.Default) {
				request.getRequestDispatcher("index.jsp").forward(
						request, response);
			}

			if (userright == User.Worker) {
				request.getRequestDispatcher("work.jsp").forward(
						request, response);
			}
			if (userright == User.Finacial) {
				request.getRequestDispatcher("finnacial.jsp").forward(
						request, response);
			}
			if (userright == User.NTManager) {
				request.getRequestDispatcher("networkmanager.jsp")
						.forward(request, response);
			}
			if (userright == User.DPManager) {
				request.getRequestDispatcher("dpmanager.jsp").forward(
						request, response);
			}
			if (userright == User.Boss) {
				request.getRequestDispatcher("boss.jsp").forward(
						request, response);
			}
		} else {
			//request.getRequestDispatcher("index.jsp").forward(request,
					//response);
		}
	} else {
		request.getRequestDispatcher("index.jsp").forward(request,
				response);
	}
%>